import * as dayjs from 'dayjs'

export const SERVER_URL = `/master`
export const PUBLIC_URL = `/public`

export const COMB_URL = '/comb'
export const COMB_URL2 = '/comb2'

export const primaryColor = '#184576'
// export const SERVER_URL = `http://localhost:4200`

/** 校验规则 */
/** Regex rules */
export const onlyNumberReg = /^[0-9]+$/
const pathReg = /^[\w\s,!"#$%&'()*+,-./ :;<=>?@[\]^`{|}~\\]+$/
const ISOorNumberReg = /^[0-9]+$|^ISO$/
const twoDecimalNumberReg = /^(0|([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/
const fourDecimalNumberReg = /^(0|([1-9][0-9]*)|(([0]\.\d{1,4}|[1-9][0-9]*\.\d{1,4})))$/
export const positiveReg = /^(0|[1-9][0-9]*)(\.[0-9]*)?$/ // 正数，包括整数和小数
export const alphanumericReg = /^[A-Za-z0-9]+$/
export const oneDecimalReg = /^-?[0-9]+(\.[0-9]{0,1})?$/
export const twoDecimalReg = /^-?[0-9]+(\.[0-9]{0,2})?$/

export const getCertainNumDecimalNumberReg = (num: number) =>
  // new RegExp('^(0|([1-9][0-9]*)|(([0]\\.\\d{1,' + num + '}|[1-9][0-9]*\\.\\d{1,' + num + '})))$')
  new RegExp('^(([1-9]{1}\\d*)|(0{1}))(\.\\d{0,' + num + '})?$', 'g')
/** 字母，数字和一些英文符号 ,!"#$%&'()*+,- ./ :;<=>?@[ ]^`{|}~ */
export const alphanumericAndSymbolsReg = /^[\w\s,!"#$%&'()*+,-.\/ :;<=>?@[\]^`{|}~]{1,}$/

export const usernameReg = /^[\da-zA-Z@.]+$/
// export const passwordReg = /^[\w-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'<>~\·`\?:;|]+$/
export const passwordReg = /^(?=.*[A-Z])+(?=.*[a-z])+(?=.*[0-9])+[A-Za-z0-9_#\$]+$/
export const usernameMinLength = 4
export const usernameMaxLength = 20
export const nicknameLength = 50
export const passwordLength = 32
export const addressMaxLength = 38
export const chanNameMaxLength = 25

/** 风控校验规则 */
export const riskControlSchemeCodeLength = 50
export const riskControlSchemeCodeReg = /^[A-Za-z0-9]+$/
export const riskControlSchemeNameLength = 50
export const riskControlSchemeRemarkLength = 50
export const riskControlRuleNameLength = 50
export const riskControlRuleMin = 1
export const riskControlRuleMax = 999999999999
export const riskControlRuleQuotaReg = /^[0-9]\d*$/
export const passwordMaxLength = 32
export const passwordMinLength = 8
export const emailMaxLength = 80
export const cityMaxLength = 50
// 参考: https://emailregex.com/
// tslint:disable-next-line: max-line-length
// export const emailReg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z0-9]{1,}))$/
export const emailReg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{1,}))$/
// acquirer insNameEN
export const insNameENReg = /^[\w\s,!"#$%&'()*+,-./ :;<=>?@[\]^`{|}~\\]+$/
// acquirer insCode
export const insCodeReg = /^[0-9]+$/
export const insNameMaxLength = 50
export const insNameENMaxLength = 50
export const insCodeLength = 8
export const contactNameMaxLength = 50
// group agentNameEN
export const agentNameENReg = /^[\w\s,!"#$%&'()*+,-./ :;<=>?@[\]^`{|}~\\]+$/
export const agentNameMaxLength = 50
export const agentNameENMaxLength = 50
// merchants merNumReg
export const merNumReg = /^[A-Za-z0-9]*$/
// merchants agentNameEN
export const merNameENReg = /^[\w\s,!"#$%&'()*+,-./ :;<=>?@[\]^`{|}~\\]+$/
export const merNumMaxLength = 32
export const merNameMaxLength = 50
export const merNameENMaxLength = 50
// store storeNum
export const storeNumReg = /^[\w\s,!"#$%&'()*+,-./ :;<=>?@[\]^`{|}~\\]*$/
// store storeNameEN
export const storeNameENReg = /^[\w\s,!"#$%&'()*+,-./ :;<=>?@[\]^`{|}~\\]+$/
export const storeNumMaxLength = 32
export const storeNameMaxLength = 50
export const storeNameENMaxLength = 50
export const storePostalCodeReg = /^\d*$/
export const detailAddressMaxLength = 300
// store - 清算
export const bankAccountNameMaxLength = 50
export const bankMaxLength = 50
export const branchCodeMaxLength = 32
export const branchCodeReg = /^[\w\s,!"#$%&'()*+,-./ :;<=>?@[\]^`{|}~\\]*$/
export const bankAccountMaxLength = 32
export const bankAccountReg = /^[\w\s,!"#$%&'()*+,-./ :;<=>?@[\]^`{|}~\\]*$/
// onlinecharge duration
export const durationReg = /^([1-9]|1[0-5])$/

export const refundAmtRegNotSupportDecimal = /^[1-9]\d*$/
export const refundAmtRegSupportDecimal = /^([1-9]\d{0,9}|0)(\.\d{1,2})?$/
// 事后风控的阈值与分值
export const postRiskThreshold = /^\d{0,8}(\.\d{1,3})?$/
export const postRiskScore = /^[1-9]{1}\d{0,2}$/

// 中文正则
export const chineseReg = /^[\u4e00-\u9fa5]*$/
// merchant
export const merchantauthPasswordReg = onlyNumberReg

/** acquirer channel */
/** ALP */
export const AlipayPartnerIDMaxLength = 64
export const AlipayPartnerIDReg = ISOorNumberReg
export const MD5KeyMaxLength = 64
export const MD5KeyReg = alphanumericReg
export const ALPAppIdMaxLength = 64
export const ALPAppIdReg = alphanumericReg
export const SFTPPathMaxLength = 64
export const SFTPPathReg = pathReg
export const SFTPUsernameMaxLength = 64
export const SFTPUsernameReg = alphanumericReg
export const SFTPPasswordMaxLength = 64
export const SFTPPasswordReg = alphanumericReg
export const TransactionFeeMaxLength = 5
export const TransactionFeeReg = fourDecimalNumberReg
export const ChannelMerchantNameMaxLength = 50
// export const ChannelMerchantNameReg = alphanumericReg
export const AlipaySecondaryMerIDMaxLength = 64
export const AlipaySecondaryMerNameMaxLength = 128
export const AlipayStoreIDMaxLength = 128
export const AlipayStoreNameMaxLength = 64


/** WXP */
export const WeChatMerchantIDMaxLength = 32
export const WeChatMerchantIDReg = alphanumericReg
export const WeChatAppIDMaxLength = 32
export const WeChatAppIDReg = alphanumericReg
export const ApiSecretMaxLength = 32
export const ApiSecretMinLength = 32
export const APiSecretReg = alphanumericReg

export const WeChatSubMerIDMaxLength = 32

/** UPI */
export const AcquiringIINMaxLength = 11
export const AcquiringIINReg = onlyNumberReg
export const ForwardingIINMaxLength = 12
export const ForwardingIINReg = onlyNumberReg
export const ChannelEncryptPublicKeyIDMaxLength = 128
export const ChannelEncryptPublicKeyIDReg = alphanumericReg
export const ChannelSignPublicKeyIDMaxLength = 128
export const ChannelSignPublicKeyIDReg = alphanumericReg

/** VIS */
export const VisaBINMaxLength = 8
export const IPMaxLength = 15
// tslint:disable-next-line: max-line-length
export const IPPattern = /^(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])$/
export const PortMaxLength = 10

/** MCC */
export const MccBINMaxLength = 9
export const MccIcaMaxLength = 8

/** AME */
export const AMEAINMaxLength = 11
export const F3SENumPattern = /^[0-9]{3}$/

/** UPI */
export const UPIAINMaxLength = 8
export const UPIAINLength = 8
export const UPIChannelRemarkMaxLength  = 500

/** TRU */
export const TruMerIDMaxLength = 25
export const TruMerIDMinLength = 2

/** 一些常用的时间 */
export const firstDayOfMonth = dayjs()
  .startOf('month')
  .format('YYYY-MM-DDTHH:mm:ssZ')
export const tomorrow = dayjs()
  .startOf('day')
  .add(1, 'day')
  .format('YYYY-MM-DDTHH:mm:ssZ')
export const today = dayjs()
  .startOf('day')
  .format('YYYY-MM-DDTHH:mm:ssZ')

/** 详情页签用户数量 */
export const detailUserNum = 5

/** 新增角色 */
export const roleNameMinLength = 2
export const roleNameMaxLength = 64
export const roleDescMaxLength = 256

export const TradeAmountMaxValue = 999999999999

/** terminal */
export const termCodeLength = 8
export const termRemarkLength = 256

/** 交易转换 */
export const customTradeSelRateLength = 8

/** 暂扣 */
export const holdRemarkMaxLength = 50

/** EC UPI */
export const EcAcquiringIINReg = alphanumericReg
export const CilEncryptPublicKeyIDMaxLength = 128
export const CilEncryptPublicKeyIDReg = alphanumericReg
export const CilSignPublicKeyIDMaxLength = 128
export const CilSignPublicKeyIDReg = alphanumericReg
export const AbbreviationMaxLength = 8

/** 新平台支持的渠道 */
export const SUPPORT_CHANNELS = new Set(['WXP', 'ALP', 'UPI', 'VIS', 'MCC', 'AME'])

/** DefaultInterceptor 拦截器放行400报错 */
export const errorWhiteUrl = ['/import/files']
/** 手工授权 */
export const CVV2Length = 3
export const ManualAuthAcctNumMinLength = 13
export const ManualAuthAcctNumMaxLength = 19
export const ManualAuthTransAmtMaxValue = 99999999
